//
//  Particle.m
//  admobandiad
//
//  Created by How Charles on 11-9-21.
//  Copyright 2011 hust. All rights reserved.
//

#import "Particle.h"

// ARMv7, Mac or Simulator use "Quad" particle

#import "CCParticleSystem.h"
#import "CCParticleExamples.h"

//#import "CCParticleSystemPoint.h"
//#import "CCParticleSystemQuad.h"

@implementation Particle
/////////////////////////////////////////////////////////////////////////////////////////////////////////


//LavaFlow.plist

+(void)playPartInScreenCenter:(id)sender name:(NSString*)name
{
	// Play a particle effect when the enemy was destroyed
	CCParticleSystem* system;
	

	system = [ARCH_OPTIMAL_PARTICLE_SYSTEM particleWithFile:name];
		

	
	
	
	CGSize winSize=[[CCDirector sharedDirector] winSize];
	
	// Set some parameters that can't be set in Particle Designer
	system.positionType = kCCPositionTypeFree;
	system.autoRemoveOnFinish = YES;
	system.position = ccp(winSize.width/2,winSize.height/2);;
	
	// Add the particle effect to the GameScene, for these reasons:
	// - self is a sprite added to a spritebatch and will only allow CCSprite nodes (it crashes if you try)
	// - self is now invisible which might affect rendering of the particle effect
	// - since the particle effects are short lived, there is no harm done by adding them directly to the GameScene
	[sender addChild:system ];
}

/////播放粒子效果
+(void)playPart2:(id)sender success:(bool)win
{
	// Play a particle effect when the enemy was destroyed
	CCParticleSystem* system;
	
	if (win) {
		system = [ARCH_OPTIMAL_PARTICLE_SYSTEM particleWithFile:@"fx-explosion2.plist"];
		
		///emitter.pex
		//system = [ARCH_OPTIMAL_PARTICLE_SYSTEM particleWithFile:@"emitter.pex"];
	}
	else {
		system = [ARCH_OPTIMAL_PARTICLE_SYSTEM particleWithFile:@"fx-explosion.plist"];
	}
	
	
	
	CGSize winSize=[[CCDirector sharedDirector] winSize];
	
	// Set some parameters that can't be set in Particle Designer
	system.positionType = kCCPositionTypeFree;
	system.autoRemoveOnFinish = YES;
	system.position = ccp(winSize.width/2,winSize.height/2);;
	
	// Add the particle effect to the GameScene, for these reasons:
	// - self is a sprite added to a spritebatch and will only allow CCSprite nodes (it crashes if you try)
	// - self is now invisible which might affect rendering of the particle effect
	// - since the particle effects are short lived, there is no harm done by adding them directly to the GameScene
	[sender addChild:system ];
}


/////播放粒子效果
+(void)playParticleQiPao:(id)sender name:(NSString *)fileName pos:(CGPoint)Pos
{
	if(qiPaoSystem != nil)
	{
		[sender removeChild:qiPaoSystem cleanup:YES];
		qiPaoSystem=nil;
	}
	
	// Play a particle effect when the enemy was destroyed
	//CCParticleSystem* qiPaoSystem;
	
	
	qiPaoSystem = [ARCH_OPTIMAL_PARTICLE_SYSTEM particleWithFile:fileName];
	
	
	
	
	CGSize winSize=[[CCDirector sharedDirector] winSize];
	
	// Set some parameters that can't be set in Particle Designer
	qiPaoSystem.positionType = kCCPositionTypeFree;
	qiPaoSystem.autoRemoveOnFinish = YES;
	qiPaoSystem.position = Pos;
	
	// Add the particle effect to the GameScene, for these reasons:
	// - self is a sprite added to a spritebatch and will only allow CCSprite nodes (it crashes if you try)
	// - self is now invisible which might affect rendering of the particle effect
	// - since the particle effects are short lived, there is no harm done by adding them directly to the GameScene
	[sender addChild:qiPaoSystem z:10];
}

/////播放粒子效果
+(void)playParticle:(id)sender name:(NSString *)fileName pos:(CGPoint)Pos
{
	// Play a particle effect when the enemy was destroyed
	CCParticleSystem* system;
	
	
	system = [ARCH_OPTIMAL_PARTICLE_SYSTEM particleWithFile:fileName];
	
	
	
	
	CGSize winSize=[[CCDirector sharedDirector] winSize];
	
	// Set some parameters that can't be set in Particle Designer
	system.positionType = kCCPositionTypeFree;
	system.autoRemoveOnFinish = YES;
	system.position = Pos;
	
	// Add the particle effect to the GameScene, for these reasons:
	// - self is a sprite added to a spritebatch and will only allow CCSprite nodes (it crashes if you try)
	// - self is now invisible which might affect rendering of the particle effect
	// - since the particle effects are short lived, there is no harm done by adding them directly to the GameScene
	[sender addChild:system z:10];
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

////////播放升级动画
+(void)displayLevelUpAnim:(id)sender
{
	CGSize size=[[CCDirector sharedDirector] winSize];
	
	CCSprite * level_up=[CCSprite spriteWithFile:@"ui_main_LV.png"];
	level_up.position=ccp(size.width/2,size.height/2);
	[sender addChild:level_up z:7 tag:0];
	
	////////定义动作
	CCMoveBy * moveBy=[CCMoveBy actionWithDuration:4 position:ccp(0,size.height)];
	//CCMoveBy * moveBy2=[CCMoveBy actionWithDuration:0.5 position:ccp(0,((winSize.height)/16))];
	CCFadeOut * fade=[CCFadeOut actionWithDuration:4];
	//CCFadeIn * fade2=[CCFadeIn actionWithDuration:0.5];
	
	CCSpawn * together=[CCSpawn actions:moveBy,fade,nil];
	
	CCCallFuncN * call=[CCCallFuncN actionWithTarget:self selector:@selector(removeSprite:)];
	
	CCSequence * seq=[CCSequence actions:together,call,nil];
	
	[level_up runAction:seq];
}


////////播放New High Score 文字
+(void)displayNewHighScoreAnim:(id)sender
{
	CGSize size=[[CCDirector sharedDirector] winSize];
	
	CCLabel * label=[CCLabelTTF labelWithString:@"New High Score" 
										  fontName:@"Marker Felt"
										  fontSize:60];
	label.color=ccc3(255, 0, 0);
	label.position=ccp(size.width/2,size.height/2);
	[sender addChild:label z:7 tag:0];
	
	////////定义动作
	CCMoveBy * moveBy=[CCMoveBy actionWithDuration:4 position:ccp(0,size.height)];
	//CCMoveBy * moveBy2=[CCMoveBy actionWithDuration:0.5 position:ccp(0,((winSize.height)/16))];
	CCFadeOut * fade=[CCFadeOut actionWithDuration:4];
	//CCFadeIn * fade2=[CCFadeIn actionWithDuration:0.5];
	
	CCSpawn * together=[CCSpawn actions:moveBy,fade,nil];
	
	CCCallFuncN * call=[CCCallFuncN actionWithTarget:sender selector:@selector(removeSprite:)];
	
	CCSequence * seq=[CCSequence actions:together,call,nil];
	
	[label runAction:seq];
}


-(void)removeSprite:(id)sender
{
	CCSprite * sprite=(CCSprite *)sender;
	
	[sender removeChild:sprite cleanup:YES];
}

-(void)callPart:(id)sender
{
	[Particle playPartInScreenCenter:self name:@"kaibaoxiang01.plist"];
}


@end
